/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.database.sql_generator;

import com.domain.Beberage;
import com.database.DatabaseTableProjectionGenerator;
import com.database.tables.BeberagesTable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Miguel
 */
public class BeberageSQLGenerator extends SQLStatementGenerator<Beberage>{

    public BeberageSQLGenerator(String inDBTable){
        super(inDBTable);
    }
    
    @Override
    public String createSelectStatement(String condition) {
        String selectStatement = "SELECT * ";
        selectStatement += "FROM " + getDatabaseTable() + " ";
        selectStatement += condition == null ? ";" : "WHERE " + condition + ";";
        return selectStatement;
    }

    @Override
    public String createUpdateStatement(Beberage prevObject, Beberage newObject) {
        String updateStatement = "UPDATE " + getDatabaseTable() + " ";
        updateStatement += " SET BeberageName = '" + newObject.getName() + "', BeberageDescription = '" + newObject.getDescription() + "'";
        updateStatement += " WHERE BeberageName = '" + prevObject.getName() + "';";
        return updateStatement;
    }

    @Override
    public String createDeleteStatement(Beberage deletingObject) {
        String deleteStatement = "DELETE FROM " + getDatabaseTable() + " ";
        deleteStatement += "WHERE " + BeberagesTable.ID_COL + " = " + deletingObject.getID() + ";--";
        return deleteStatement;
    }

    @Override
    public String createInsertStatement(Beberage insertingObject) {
        String insertStatement = "INSERT INTO " + getDatabaseTable() + " (idBeberage,BeberageName,BeberageDescription,RegisterDate)";
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm");
        Date actualDate = new Date();
        insertStatement += " VALUES(nextval('Beberage_ID_Sequence'),'" +
                insertingObject.getName() + "','"+insertingObject.getDescription()+
                "','"+dateFormat.format(actualDate)+"');";
        return insertStatement;
    }
}
